<?php
include "../config/koneksi.php";

$qry = mysql_query("SELECT * FROM inbox WHERE Processed='false' LIMIT 0,1");
$gq = mysql_fetch_object($qry);

$inid = $gq->ID;
$sender = $gq->SenderNumber;
$keyword = strtoupper(str_replace("'","\'",$gq->TextDecoded));

if(!empty($keyword)) {
	$kw = explode(".",$keyword);
		if($kw[0] == 'REG') {
			if($kw[1] == 'INFO') {
				$infox = "Untuk mendaftar silakan ketik REG.NAMA_LENGKAP.JENIS_KELAMIN.ASAL_KOTA.NO_HP. Contoh : REG.HENRY.L.JAKARTA.0813274XXXX";
				exec('c:\xampp\htdocs\bosms\gammu\gammu-smsd-inject.exe -c c:\xampp\htdocs\bosms\gammu\smsdrc EMS '.$sender.' -text "'.$infox.'"');
				mysql_query("UPDATE inbox SET Processed='true' WHERE ID='$inid'");
			}
			else {
				$qrx = mysql_query("INSERT INTO anggota VALUES('','$kw[1]','$kw[2]','$kw[3]','$kw[4]',NOW())");
				if($qrx) {
					$pesanx = "Terima kasih, Pendaftaran berhasil. Data Anda telah kami simpan";
					exec('c:\xampp\htdocs\bosms\gammu\gammu-smsd-inject.exe -c c:\xampp\htdocs\bosms\gammu\smsdrc EMS '.$sender.' -text "'.$pesanx.'"');
					mysql_query("UPDATE inbox SET Processed='true' WHERE ID='$inid'");
				}
			}
		}
		else {
			$psn = "Maaf, kata kunci yang Anda masukkan salah. ketik REG.INFO untuk petunjuk";
			exec('c:\xampp\htdocs\bosms\gammu\gammu-smsd-inject.exe -c c:\xampp\htdocs\bosms\gammu\smsdrc EMS '.$sender.' -text "'.$psn.'"');
			mysql_query("UPDATE inbox SET Processed='true' WHERE ID='$inid'");
		}
}
?>